package com.whitedust.top100;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author A
 * @since 2025/11/17 19:13
 */

public class Top97 {
    public boolean wordBreak(String s, List<String> wordDict) {
        Set<String> set = new HashSet<>();
        for (String word : wordDict) {
            set.add(word);
        }
        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i && !dp[i]; j++) {
                if (set.contains(s.substring(j, i)) && dp[j]) dp[i] = true;
            }
        }
        return dp[s.length()];
    }
}
